<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
    <script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
    <title>Detection Result</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            padding: 20px;
            background-color: black;
        }

        .content {
        }

        .output {
            display: flex;
            flex-wrap: wrap;
        }
        .output-panel {
            flex: 0 1 calc(50% - 20px); /* 每个板块占据一半宽度，减去间距 */
            margin: 10px;
            padding: 20px;
            border: 1px solid #ccc;
            border-radius: 5px;
            background-color: #f9f9f9;
            position: relative;
        }
        .output-panel h3 {
            margin-bottom: 15px;
        }
        .model-result {
            margin-bottom: 20px;
        }
        .final-result {
            margin-top: 20px;
            padding: 10px;
            border: 2px solid #000;
            border-radius: 5px;
            background-color: #ffeeba;
            font-size: 1.2em;
            font-weight: bold;
            text-align: center;
            position: absolute;
            bottom: 10px;
            left: 50%;
            transform: translateX(-50%);
        }
        canvas {
            width: 100%;
            height: auto;
        }


        nav a {
            margin-right: 15px;
            text-decoration: none;
            color: #007BFF;
        }
        nav a:hover {
            text-decoration: underline;
        }













        /*特殊下划线按钮*/
        .hover-button {
            position: relative;
            display: inline-block;
            padding: 10px 20px;
            font-size: 16px;
            text-decoration: none;
            color: #333;
            border: none; /* 移除边框 */
            background: none; /* 确保没有背景 */
            transition: all 0.3s ease;
        }

        .hover-button::after {
            content: '';
            position: absolute;
            left: 0;
            bottom: 0;
            width: 0;
            height: 2px;
            background-color: #333;
            transition: width 0.3s ease;
        }

        .hover-button:hover {
            transform: translateY(-3px);
        }

        .hover-button:hover::after {
            width: 100%;
        }


        .hover-button_dao {
            position: relative;
            display: inline-block;
            padding: 10px 20px;
            font-size: 16px;
            text-decoration: none;
            color: #333;
            border: none; /* 移除边框 */
            background: none; /* 确保没有背景 */
            transition: all 0.3s ease;
        }

        .hover-button_dao::after {
            content: '';
            position: absolute;
            left: 0;
            bottom: 0;
            width: 0;
            height: 2px;
            background-color: white;
            transition: width 0.3s ease;
        }

        .hover-button_dao:hover {
            transform: translateY(-3px);
        }

        .hover-button_dao:hover::after {
            width: 100%;
        }

        /* 导航栏 */
        .navbar {
            position: fixed;
            top: 0;
            left: 0;
            width: 100%;
            background-color: #333;
            color: white;
            padding: 15px;
            text-align: center;
            transition: transform 0.3s ease;
            display: flex;
            justify-content: space-between;
            align-items: center;
            z-index: 1000;
            border-bottom-left-radius: 20px; /* 添加下方左边角的弧度 */
            border-bottom-right-radius: 20px; /* 添加下方右边角的弧度 */
            opacity: 0.7;

        }

        .navbar.hidden {
            transform: translateY(-100%);
        }
        
        .background-container {
            position: fixed; /* 固定定位，使容器不随页面滚动而移动 */
            top: 0;
            left: 0;
            width: 100%; /* 宽度充满整个视口 */
            height: 200%; /* 高度充满整个视口 */
            background: url('./static/nightcity.jpg') no-repeat center center;
            /* 兼容浏览器版本 */
            -webkit-background-size: cover;
            -o-background-size: cover;                
            background-size: cover;
            z-index: -1; /* 将容器置于页面底部，以便其他内容可以覆盖在其上 */
            opacity: 0.6;
        }
    </style>
</head>
<body>
    <div class="background-container"></div>

    <div class="navbar" id="navbar">
        <div><p, style="
            font-size: 25px;
            position: absolute;
            top: 70%; /* 从顶部偏移50% */
            left: 50%; /* 从左边偏移50% */
            transform: translate(-50%, -50%); /* 使用变换来精确居中 */
            color: white;
            ">啦啦啦
            </p></div>
        <div>
            <button>
                <a href="{{ url_for('index_page') }}" class="hover-button_dao", style="
                    position: absolute;
                    top:10%;
                    left: 5%;
                    color: white;            
                    " data-sound="./static/Speech_Assistant/home.wav">主页</a>
            </button>
            <button>
                <a href="{{ url_for('index_page') }}", class="hover-button_dao", style="
                    position: absolute;
                    top:10%;
                    right: 5%;
                    color: white;            
                    " data-sound="./static/Speech_Assistant/about.wav">关于我们</a>
            </button>
            <button>
                <a href="{{ url_for('index_page') }}", class="hover-button_dao", style="
                    position: absolute;
                    top:10%;
                    right: 15%;
                    color: white;            
                    " data-sound="./static/Speech_Assistant/add_credit.wav">充值服务</a>
            </button>
        </div>
    </div>

    
    <div class="content" id="content1", style="
        position: relative;
        top: 100px;
    ">
        <h1>
            <p, style="
                color: wheat;
            ">Detection Result for {{ filename }}
            </p>
        </h1>

        {% if output %}
            <!-- <h2>Output:</h2>  -->
            <div class="output", style="
                opacity: 0.8;
            ">
                {% for op_name, result in output.items() %}
                    <div class="output-panel">
                        <h3>{{ op_name }}</h3>
                        <canvas id="chart-{{ op_name }}" width="400" height="200"></canvas>
                        <div class="model-results">
                            {% for model_result in result.model_results %}
                                <div class="model-result">
                                    <h4>{{ model_result['model'] }}</h4>
                                    <p><strong>Check Result:</strong> {{ model_result['check result'] }}</p>
                                    <p><strong>Percent:</strong> {{ model_result['percent'] }}</p>
                                </div>
                            {% endfor %}
                        </div>
                        <div class="final-result">
                            <strong>Final Result:</strong> {{ result.final_result }}
                        </div>
                    </div>
                {% endfor %}
            </div>
        {% endif %}

        {% if error %}
            <h2>Error:</h2>
            <div class="error">
                {% for op_name, err in error.items() %}
                    <div class="error-item">
                        <h3>{{ op_name }}</h3>
                        <pre>{{ err }}</pre>
                    </div>
                {% endfor %}
            </div>
        {% endif %}
    </div>
    

    <nav>
        <a href="{{ url_for('main') }}">Home</a>
    </nav>

    <script>
        document.addEventListener('DOMContentLoaded', function () {
            {% for op_name, result in output.items() %}
                var ctx = document.getElementById('chart-{{ op_name }}').getContext('2d');
                var percentValues = [];
                var labels = [];

                {% for model_result in result.model_results %}
                    percentValues.push(parseFloat('{{ model_result['percent'] }}'));
                    labels.push('{{ model_result['model'] }}');
                {% endfor %}

                var minValue = Math.min(...percentValues);
                var maxValue = Math.max(...percentValues);

                var chart = new Chart(ctx, {
                    type: 'bar',
                    data: {
                        labels: labels,
                        datasets: [{
                            label: 'Percent',
                            data: percentValues,
                            backgroundColor: '#36A2EB'
                        }]
                    },
                    options: {
                        scales: {
                            y: {
                                beginAtZero: true, // 确保从0开始
                                min: Math.min(0, minValue), // 动态调整最小值
                                max: Math.max(0, maxValue)  // 动态调整最大值
                            }
                        },
                        animation: {
                            duration: 1000, // 动画持续时间，单位为毫秒
                            easing: 'easeOutBounce' // 动画效果
                        }
                    }
                });
            {% endfor %}
        });


        
    </script>
</body>


<script>
    // 监听滚动事件
    
    // 变量来跟踪content2的状态
    let content2Visible = false;
    let lastScrollPos = window.scrollY;


    let lastScrollTop = 0;
    const navbar = document.getElementById('navbar');
    window.addEventListener('scroll', function() {
            const currentScrollPos = window.scrollY;
            lastScrollPos = currentScrollPos;

            let scrollTop = window.pageYOffset || document.documentElement.scrollTop;

                if (scrollTop > lastScrollTop) {
                    // 向下滚动
                    navbar.classList.add('hidden');
                } else {
                    // 向上滚动
                    navbar.classList.remove('hidden');
                }

            lastScrollTop = scrollTop <= 0 ? 0 : scrollTop; // For Mobile or negative scrolling



            var container1Shown = false;
            var container2Shown = false;
            var container3Shown = false;

            var scrollPosition = window.scrollY;


            const scrollPosition2 = window.pageYOffset;
            const backgroundContainer = document.querySelector('.background-container');
            backgroundContainer.style.transform = 'translateY(' + -scrollPosition2 * 0.5 + 'px)';


        });
</script>
</html>
